package example.com.nexd.collectionsdk.sdk.utils;

import android.content.Context;
import android.os.Environment;

import java.io.File;

/**
 * FileUtils create by codingfish at 15/4/23
 * TODO:
 *
 * @Version V1.0
 */
public class FileUtils {
    public static File getDiskCacheDir(Context context, String uniqueName) {
        System.out.print("");
        String cachePath = ExternalStorageHelper.getCacheDir(context).getPath();
//        if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
//                || !Environment.isExternalStorageRemovable()) {
//            // /sdcard/Android/data/<application package>/cache
//            cachePath = context.getExternalCacheDir().getPath();
//        } else {
//            // /data/data/<application package>/cache
//            cachePath = context.getCacheDir().getPath();
//        }
        return new File(cachePath + File.separator + uniqueName);
    }

    public static File getCacheDir(Context context) {
        File dir;
        if (isExternalStorageWritable()) {
            dir = context.getExternalCacheDir();
        } else {
            dir = context.getCacheDir();
        }
        // 問題出在這一行 !Core.java:84
        if (!dir.exists()) {
            dir.mkdirs();
        }
        return dir;
    }

    public static boolean isExternalStorageWritable() {
        return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
    }
}
